<?php
namespace app\models;

use Yii;
use yii\db\ActiveRecord;

class feedback extends ActiveRecord{
      public static function tableName(){
            return "{{%feedback}}";
        }
      
      public function rules(){
         return[
             ['openid','required','message' => 'openid不能为空~'],
             ['content','required','message' => '提交的内容不能为空~'],
             ['content','string','max' => 300 ],
           ];
        }

      public function add($data){
           if($data){
                //创建时间
              date_default_timezone_set('PRC');
              $createtime = date('Y-m-d H:i:s');
             
               //输入数据库
              $this->openid = $data['openid'];
              $this->content = $data['content'];
              $this->topicId = $data['topicId'];  //反馈题目
              $this->state = $data['state'];  //1:没看懂 2:没找到  3:bug反馈
              $this->createTime = $createtime;
              $result = $this->save();
              if($result){
                   $error = 0;
                   return $error;
              }else{
                   $error = $this->getErrors();
                   return $error;
                }
            }else{
                   $error = 2;
                   return $error;
           }
    }
}
